package pl.edu.agh.gronoMining.owlToGraphConverter.graph;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import org.jgrapht.graph.SimpleGraph;

public class Graph {
	
	private org.jgrapht.Graph<Vertex,Edge> simpleGraph;
	private int number = 0;
	private Map<Integer, Vertex> vertexMap;
	private int id = 0;
	
	public Graph() {		
		simpleGraph = new SimpleGraph<Vertex,Edge>(new EdgeFactoryImpl());
		vertexMap = new HashMap<Integer, Vertex>();
	}
	
	public int addNode(int type, int nodeLabel, String text) {
		Vertex v = new Vertex(number, type, nodeLabel, text);
		vertexMap.put(number, v);
		simpleGraph.addVertex(v);
		return number++;
	}
	
	public int addNode(int type, int nodeLabel) {
		return addNode(type, nodeLabel, "");
	}
	
	public void addEdge(int node1, int node2) {
		simpleGraph.addEdge(vertexMap.get(node1), vertexMap.get(node2));
	}
	
	public boolean hasEdge(int node1, int node2) {
		Edge e = simpleGraph.getEdge(vertexMap.get(node1), vertexMap.get(node2));
		if (e == null)
			return false;
		return true;
	}
	
	public Set<Edge> edgeSet() {
		return simpleGraph.edgeSet();
	}
	
	public Set<Vertex> vertexSet() {
		return simpleGraph.vertexSet();
	}
	
	public org.jgrapht.Graph<Vertex,Edge> getSimpleGraph() {
		return simpleGraph;
	}
	
	public void setId(int id) {
		this.id = id;
	}
	
	public String toString() {
		return "graph "+id;
	}
}
